package com.aaa.controller.fpa;

import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.Result;

import com.aaa.entity.fpa.TestPlanFpa;
import com.aaa.entity.PageSortEntity;
import com.aaa.service.fpa.TestPlanFpaService;
import com.github.pagehelper.Page;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 测试计划fpa(TestPlanFpa)表控制层
 *
 * @author
 * @since 2022-08-31 11:41:17
 */
@RestController
@RequestMapping("testPlanFpa")
public class TestPlanFpaController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TestPlanFpaService testPlanFpaService;


    /**
     * 去显示所有测试计划的页面
     */
    /*@RequestMapping("toShowTestPlanFpa.do")
    public ModelAndView toShowTestPlanFpa(ModelAndView modelAndView){
        modelAndView.setViewName("fpa/showTestPlanFpa");
        return  modelAndView;
    }*/

    //分页查询
    @RequestMapping(value = "queryByPage.do", method = RequestMethod.GET)
    public Result queryAllUserPage(PageSortEntity pageSortEntity, TestPlanFpa testPlanFpa) {
        Page page = testPlanFpaService.queryAll(pageSortEntity, testPlanFpa);
        return success(page.getResult(), page.getTotal());
    }

    /**
     * 添加测试计划的页面
     */
    @LogMonitor
    @PostMapping("insert.do")
    public Result add(TestPlanFpa testPlanFpa) {
        TestPlanFpa insert = this.testPlanFpaService.insert(testPlanFpa);
        return success(insert);
    }

    //修改
    @LogMonitor
    @RequestMapping("/update.do")
    @ResponseBody
    public Result update(TestPlanFpa testPlanFpa) {
        boolean update = this.testPlanFpaService.update(testPlanFpa);
        if (update) {
            return success();
        } else {
            return fail();
        }
    }


    //删除
    @LogMonitor
    @RequestMapping("/delete.do")
    @ResponseBody
    public Result delete(String[] ids) {
        List list = new ArrayList();
        for (String id : ids) {
            list.add(id);
        }
        boolean user1 = testPlanFpaService.delete(list);
        if (user1) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * 添加时查询是否重名测试计划的页面
     */
    @GetMapping("repetitionName.do")
    public Result repetitionName(TestPlanFpa testPlanFpa) {
        boolean b = this.testPlanFpaService.repetitionName(testPlanFpa);
        if (b) {
            return success("测试名称可用");
        }
        return fail("测试名称重复，不可用");
    }
}

